#!/bin/bash

# pass any -X and -D option to java
while [[ $1 == "-X"* ]] || [[ $1 == "-D"* ]] ; do
  JAVA_OPTS="${JAVA_OPTS} $1"
  shift
done
if [[ $JAVA_OPTS != *"-Xmx"* ]] ; then
   if [[ $1 == "import" ]] ; then
     JAVA_OPTS="$JAVA_OPTS -Xmx1024m"
   else
     JAVA_OPTS="$JAVA_OPTS -Xmx256m"
   fi
fi

#resolve INSTALLDIR, since $0 can be a symlink
PRG="$0"
while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done
INSTALLDIR=`dirname "$PRG"`

echo "Starting Java with: $JAVA_OPTS"
java $JAVA_OPTS -classpath "$INSTALLDIR/target/jdbcimage.jar:$INSTALLDIR/lib/*" pz.tool.jdbcimage.main.JdbcImageMain "$@"
